package com.ruoyi.service.inventory.impl;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.inventory.MesInventoryRecord;
import com.ruoyi.mapper.inventory.MesInventoryRecordMapper;
import com.ruoyi.service.inventory.IMesInventoryRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 库存记录Service业务层处理
 * 
 * @author ruoyi
 */
@Service
public class MesInventoryRecordServiceImpl implements IMesInventoryRecordService {
    @Autowired
    private MesInventoryRecordMapper mesInventoryRecordMapper;

    /**
     * 查询库存记录
     * 
     * @param recordId 库存记录主键
     * @return 库存记录
     */
    @Override
    public MesInventoryRecord selectMesInventoryRecordByRecordId(Long recordId) {
        return mesInventoryRecordMapper.selectMesInventoryRecordByRecordId(recordId);
    }

    /**
     * 查询库存记录列表
     * 
     * @param mesInventoryRecord 库存记录
     * @return 库存记录
     */
    @Override
    public List<MesInventoryRecord> selectMesInventoryRecordList(MesInventoryRecord mesInventoryRecord) {
        return mesInventoryRecordMapper.selectMesInventoryRecordList(mesInventoryRecord);
    }

    /**
     * 校验记录编号是否唯一
     * 
     * @param recordCode 记录编号
     * @return 结果
     */
    @Override
    public String checkRecordCodeUnique(String recordCode, Long recordId) {
        MesInventoryRecord record = mesInventoryRecordMapper.checkRecordCodeUnique(recordCode, recordId);
        if (StringUtils.isNotNull(record)) {
            return "1";
        }
        return "0";
    }

    /**
     * 根据物料编码查询库存记录
     * 
     * @param materialCode 物料编码
     * @return 库存记录集合
     */
    @Override
    public List<MesInventoryRecord> selectRecordsByMaterialCode(String materialCode) {
        return mesInventoryRecordMapper.selectRecordsByMaterialCode(materialCode);
    }

    /**
     * 根据仓库编码查询库存记录
     * 
     * @param warehouseCode 仓库编码
     * @return 库存记录集合
     */
    @Override
    public List<MesInventoryRecord> selectRecordsByWarehouseCode(String warehouseCode) {
        return mesInventoryRecordMapper.selectRecordsByWarehouseCode(warehouseCode);
    }

    /**
     * 根据关联单号查询库存记录
     * 
     * @param relatedCode 关联单号
     * @return 库存记录集合
     */
    @Override
    public List<MesInventoryRecord> selectRecordsByRelatedCode(String relatedCode) {
        return mesInventoryRecordMapper.selectRecordsByRelatedCode(relatedCode);
    }

    /**
     * 新增库存记录
     * 
     * @param mesInventoryRecord 库存记录
     * @return 结果
     */
    @Override
    public int insertMesInventoryRecord(MesInventoryRecord mesInventoryRecord) {
        return mesInventoryRecordMapper.insertMesInventoryRecord(mesInventoryRecord);
    }

    /**
     * 修改库存记录
     * 
     * @param mesInventoryRecord 库存记录
     * @return 结果
     */
    @Override
    public int updateMesInventoryRecord(MesInventoryRecord mesInventoryRecord) {
        return mesInventoryRecordMapper.updateMesInventoryRecord(mesInventoryRecord);
    }

    /**
     * 批量删除库存记录
     * 
     * @param recordIds 需要删除的数据主键集合
     * @return 结果
     */
    @Override
    public int deleteMesInventoryRecordByRecordIds(Long[] recordIds) {
        return mesInventoryRecordMapper.deleteMesInventoryRecordByRecordIds(recordIds);
    }

    /**
     * 删除库存记录信息
     * 
     * @param recordId 库存记录主键
     * @return 结果
     */
    @Override
    public int deleteMesInventoryRecordByRecordId(Long recordId) {
        return mesInventoryRecordMapper.deleteMesInventoryRecordByRecordId(recordId);
    }
}